package com.rxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rxt.common.result.Result;
import com.rxt.model.domain.FBank;
import com.rxt.mapper.FBankMapper;
import com.rxt.model.domain.FBankUser;
import com.rxt.model.dto.UUserDto;
import com.rxt.model.vo.*;
import com.rxt.service.IFBankService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 周梓文
 * @since 2023-08-24
 */
@Service
public class FBankServiceImpl extends ServiceImpl<FBankMapper, FBank> implements IFBankService {


    @Override
    public Result insert(BankVo bankVo) {
        FBank fBank = new FBank();
        BeanUtils.copyProperties(bankVo,fBank);

        this.save(fBank);
        return Result.ok(fBank);
    }

    @Override
    public Result updateBankById(BankVo bankVo) {
        FBank fBank = new FBank();
        BeanUtils.copyProperties(bankVo,fBank);

        this.updateById(fBank);
        return Result.ok(fBank);
    }

    @Override
    public Result getOneByID(Long id) {
        FBank one = this.getOne(new LambdaQueryWrapper<FBank>().eq(FBank::getId, id));
        if (one == null){
            return Result.fail("没有该银行");
        }
        return Result.ok(one);
    }

    @Override
    public Result getPage(BankPageVo page) {
        Page<FBank> fBankPage = new Page<>(page.getPage(), page.getPageSize());

        this.page(fBankPage);

        return Result.ok(page);
    }

    @Override
    public Result dedleteById(Long id) {
        this.removeById(id);
        return Result.ok("删除成功");
    }
}
